﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFHotKeyCommand.Examples
{
    /// <summary>
    /// Example1.xaml 的交互逻辑
    /// </summary>
    public partial class Example1 : Window
    {
        public Example1()
        {
            InitializeComponent();
        }

        private void CommandBinding_Increase_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (textBlock1.FontSize > 50)
            {
                e.CanExecute = false;
            }
            else
            {
                e.CanExecute = true;
            }
        }

        private void CommandBinding_Increase_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            textBlock1.FontSize += 5;
        }

        private void CommandBinding_Decrease_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (textBlock1.FontSize <= 5)
            {
                e.CanExecute = false;
            }
            else
            {
                e.CanExecute = true;
            }
        }

        private void CommandBinding_Decrease_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            textBlock1.FontSize -= 5;
        }

        private void CommandBinding_Color_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void CommandBinding_Color_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Random rd = new Random();
            textBlock1.Foreground = new SolidColorBrush(
                Color.FromRgb(
                    (byte)rd.Next(0, 255),
                    (byte)rd.Next(0, 255),
                    (byte)rd.Next(0, 255))
                    );
        }
    }
}
